//
//  QrCodeWebView.m
//  BaseFrame
//
//  Created by appleLJ on 2017/11/21.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "QrCodeWebView.h"

@interface QrCodeWebView ()

@property(nonatomic,strong) UIWebView *webView;

@end

@implementation QrCodeWebView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.alpha = 0;
        UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        backButton.backgroundColor = [UIColor blackColor];
        backButton.alpha = .6;
        backButton.titleLabel.font = DEF_FontSize_13;
        [backButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:backButton];
        
        self.webView = [[UIWebView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 200) / 2, (SCREEN_HEIGHT - 200) / 2 - 50 , 200 , 200 )];
        self.webView.userInteractionEnabled = NO;
        
        [self addSubview:self.webView];
    }
    return self;
}


//出现
-(void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.nameString]]];
        self.alpha = 1;
    }];
}

//消失
-(void)dismiss{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
